package com.ny.zmb.glxt.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ny.zmb.glxt.entity.PmArea;
import com.ny.zmb.glxt.mapper.PmAreaMapper;
import com.ny.zmb.glxt.service.IPmAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collections;
import java.util.List;

@Slf4j
@Service
public class PmAreaServiceImpl extends ServiceImpl<PmAreaMapper, PmArea> implements IPmAreaService {
    @Resource
    private PmAreaMapper pmAreaMapper;
    QueryWrapper<PmArea> queryWrapper = new QueryWrapper<>();

    @Override
    public List<PmArea> selectAllByLevel(Integer level) {
        queryWrapper = new QueryWrapper<>();
        if (level == null) {
            level = 1;
        }
        queryWrapper.eq("level", level);
        return pmAreaMapper.selectList(queryWrapper);

    }

    @Override
    public List<PmArea> selectAllByLevelWithPid(Integer level, Integer pid) {
        queryWrapper = new QueryWrapper<>();
        if (level != null) {
            queryWrapper.eq("level", level);
        }
        if (pid != null) {
            queryWrapper.eq("pid", pid);
        }
        if (level == null && pid == null) {
            queryWrapper.eq("level", 1);
        }
        return pmAreaMapper.selectList(queryWrapper);
    }
}
